package controller;

import org.junit.Test;
import pojo.CheckInRecord;
import pojo.CheckInRecord;
import service.CheckInRecordService;
import service.CheckInRecordServiceImpl;
import service.StudentService;
import service.StudentServiceImpl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;


public class CheckInRecordController {
    private CheckInRecordService service = new CheckInRecordServiceImpl();
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    /*
        查询所有入住信息
     */
    @Test
    public void findAll() {
        ArrayList<CheckInRecord> list = service.findAll();
        for(CheckInRecord checkInRecord : list) {
            System.out.println(checkInRecord);
        }
    }

    /*
        条件查询，根据id查询入住信息
     */
    @Test
    public void findById() {
        CheckInRecord checkInRecord = service.findById(1);
        System.out.println(checkInRecord);
    }

    /*
        添加入住信息
     */
    @Test
    public void insert() {
        CheckInRecord checkInRecord = null;
        try {
            checkInRecord = new CheckInRecord(6,100006,101,3,simpleDateFormat.parse("2022-03-05"),simpleDateFormat.parse("2022-03-07"),new BigDecimal(1400),new BigDecimal(0),true,new BigDecimal(100));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int result = service.insert(checkInRecord);

        if(result!=0) {
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改入住信息
     */
    @Test
    public void update() {
        CheckInRecord checkInRecord = service.findById(6);
       checkInRecord.setActual_payment(new BigDecimal(1400));

        int result = service.update(checkInRecord);

        if(result != 0) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    /*
        删除入住信息
     */
    @Test
    public void delete() {
        int result = service.delete(service.findById(6));

        if(result != 0) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
